﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace EmotionPlotter
{
    /// <summary>
    /// Interaction logic for PlotEmotion.xaml
    /// </summary>
    public partial class PlotEmotion : Window
    {
        public PlotEmotion()
        {
            InitializeComponent();
           
            myBrush.ImageSource =
                new BitmapImage(new Uri("pack://application:,,,/Images/Plutchik-wheel-of-emotion.jpg"));


            hand.Height = 1590 / 3;
            hand.Width = 1600 / 3;


            hand.Fill = myBrush;

            Canvas.SetLeft(hand, 0);
            Canvas.SetTop(hand, 0);
            canvas1.Children.Add(hand);

            Canvas.SetLeft(hand, 0);
            Canvas.SetTop(hand, 0);
            canvas1.Children.Add(mark);
        }

        private System.Threading.SynchronizationContext _context = System.Threading.SynchronizationContext.Current;

        ImageBrush myBrush = new ImageBrush();
        Ellipse hand = new Ellipse();
        Ellipse mark = new Ellipse();
        Thickness _LocationMoment;

        //#error put limits
        public Point LocationMomentPtr
        {
            set
            {
                this._context.Send(o =>
                    {
                        _LocationMoment = new Thickness(value.X + 1600 / 3 / 2, value.Y + 1890 / 3 / 2, 0, 0);


                        hand.Height = 1590 / 3;
                        hand.Width = 1600 / 3;


                        hand.Fill = myBrush;

                        Canvas.SetLeft(hand, 0);
                        Canvas.SetTop(hand, 0);
                       


                        mark.Height = 20;
                        mark.Width = 20;
                        mark.Fill = Brushes.Red;

                        Canvas.SetLeft(mark, _LocationMoment.Left - mark.Width / 2);
                        Canvas.SetTop(mark, _LocationMoment.Top - mark.Height * 3);
                         
                    }, null);
            }
        }

        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            /*
            Ellipse hand = new Ellipse();


            ImageBrush myBrush = new ImageBrush();
            myBrush.ImageSource =
                new BitmapImage(new Uri("pack://application:,,,/Images/Plutchik-wheel-of-emotion.jpg"));

            hand.Height = 1590 / 3;
            hand.Width = 1600 / 3;


            hand.Fill = myBrush;

            Canvas.SetLeft(hand, 0);
            Canvas.SetTop(hand, 0);
            canvas1.Children.Add(hand);

            Ellipse mark = new Ellipse();
            mark.Height = 20;
            mark.Width = 20;
            mark.Fill = Brushes.Red;

            Canvas.SetLeft(mark, _LocationMoment.Left - mark.Width / 2);
            Canvas.SetTop(mark, _LocationMoment.Top - mark.Height * 3);
            canvas1.Children.Add(mark);
            // _LocationMoment= new Thickness(_LocationMoment.Left + this.image1.RenderSize.Width / 2 - ellipse1.Width / 2, _LocationMoment.Top + this.image1.RenderSize.Height / 2 - ellipse1.Height / 2, 0, 0);

            // ellipse1.Margin = _LocationMoment;

            //  WriteableBitmap bitmap = new WriteableBitmap((int)this.image1.RenderSize.Width, (int)this.image1.RenderSize.Height, 96, 96, PixelFormats.Bgra32, null);
            //  bitmap.Lock();
            //  bitmap.AddDirtyRect(new Int32Rect((int)_LocationMoment.Left+40, (int)_LocationMoment.Top+40, 80, 80));
            //  bitmap.Unlock();
            //  this.image1.Source = bitmap;
            */
        }
    }
}
